const router = require("koa-router")({ prefix: "/api" });
const { exportByInvest } = require("../controller/exportExcel");

router.get("/download", async (req, res) => {
  try {
    const { companyName } = req.query;

    const buffer = await exportByInvest(companyName);
    req.response.set(
      "Content-Type",
      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;utf-8"
    );
    req.response.set("Content-Disposition", `attachment;`);//设置文件下载方式:以附件方式下载
    req.response.body = buffer;

  } catch (err) {
    console.error(err);
    req.response.status = 500;
    req.response.body = err.message;
  }
});
module.exports = router;
